package com.ocom.payhandle.vo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.annotation.TableField;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.ocom.common.entity.human.EntityPersonnelPalmprint;
import lombok.Data;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
@Data
public class PersonnelInfoVo {

    private Integer pId;

    private String pName;

    private String pPhotoUrl2;

    private Integer state=0;

    private String cardNo;

    private Integer accTypeId;

    private Integer cardState;

    private String pPhotoUrl;

    private String feature;

    private String feature2;

    @TableField(exist = false)
    private List<EntityPersonnelPalmprint> palmList = new ArrayList<>();

    public PersonnelInfoVo mergeWith(PersonnelInfoVo other) {
        Field[] fields = this.getClass().getDeclaredFields();
        for (Field field : fields) {
            try {
                field.setAccessible(true);
                Object thisValue = field.get(this);
                Object otherValue = field.get(other);

                // 只有当this对象对应属性为空，且other对象对应属性非空时，才进行复制
                if (thisValue == null && otherValue != null) {
                    field.set(this, otherValue);
                }
            } catch (IllegalAccessException e) {
                // 处理反射访问异常
                throw new RuntimeException("Failed to merge properties due to IllegalAccessException", e);
            }
        }

        return this;
    }
}
